//
//  UPRepaymentCarouseCell.m
//  Uang Pasti
//
//  Created by 李永彬 on 2025/8/24.
//

#import "UPGoToApplyCarouseCell.h"
@interface UPGoToApplyCarouseCell ()

@property (nonatomic, strong) UIImageView *containerImageView;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *certiButton;
@property (nonatomic, strong) UIButton *complatedButton;

@end

@implementation UPGoToApplyCarouseCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self commonInitSubviews];
    }
    return self;
}

- (void)commonInitSubviews {
    [self.containerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.trailing.leading.equalTo(self).inset(28);
        make.height.mas_equalTo(39);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(129);
//        make.width.mas_equalTo(134);
    }];
    
    [self.certiButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.height.mas_equalTo(36);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    [self.complatedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.certiButton);
    }];
}

- (UIImageView *)containerImageView {
    if (!_containerImageView) {
        _containerImageView = [[UIImageView alloc] init];
        _containerImageView.contentMode = UIViewContentModeScaleAspectFill;
        _containerImageView.image = [UIImage imageNamed:@"go_to_apply_cell_bg"];
        _containerImageView.userInteractionEnabled = YES;
        [self addSubview:_containerImageView];
    }
    return _containerImageView;
}

- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.contentMode = UIViewContentModeScaleAspectFit;
        _iconImageView.image = [UIImage imageNamed:@"cer_public_normal"];
        [self addSubview:_iconImageView];
    }
    return _iconImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _titleLabel.backgroundColor = [UIColor colorWithHexString:@"#FD6002"];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
        _titleLabel.layer.masksToBounds = true;
        _titleLabel.layer.cornerRadius = 19.5;
        _titleLabel.layer.borderWidth = 2.0;
        _titleLabel.layer.borderColor = [[UIColor colorWithHexString:@"#000000"] CGColor];
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UIButton *)certiButton {
    if (!_certiButton) {
        _certiButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_certiButton setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_certiButton setTitle:LocalizableForKey(@"Go Certified") forState:UIControlStateNormal];
        _certiButton.titleLabel.font = [UIFont systemFontOfSize:11 weight:400];
        [_certiButton setImage:[UIImage imageNamed:@"history_apply_arrow"] forState:UIControlStateNormal];
        _certiButton.layer.masksToBounds = true;
        _certiButton.layer.cornerRadius = 18;
        _certiButton.backgroundColor = [UIColor colorWithHexString:@"#000000"];
        _certiButton.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
        _certiButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
        CGFloat imageInsetRight = 10.0f;
        _certiButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -imageInsetRight);
        [self addSubview:_certiButton];
    }
    return _certiButton;
}

- (UIButton *)complatedButton {
    if (!_complatedButton) {
        _complatedButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_complatedButton setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_complatedButton setTitle:LocalizableForKey(@"Certified") forState:UIControlStateNormal];
        _complatedButton.titleLabel.font = [UIFont systemFontOfSize:11];
        _complatedButton.layer.masksToBounds = true;
        _complatedButton.layer.cornerRadius = 18;
        _complatedButton.backgroundColor = [UIColor colorWithHexString:@"#0FE300"];
        _complatedButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
        [self addSubview:_complatedButton];
    }
    return _complatedButton;
}

- (void)setStultiiveModel:(StultiiveModel *)stultiiveModel {
    _stultiiveModel = stultiiveModel;
    self.titleLabel.text = stultiiveModel.musetic;
    if ([stultiiveModel.septuagentic isEqual: @1]) {
        self.complatedButton.hidden = NO;
        self.certiButton.hidden = YES;
    } else {
        self.complatedButton.hidden = YES;
        self.certiButton.hidden = NO;
    }
    
    NSString *imageName = nil;
    if ([stultiiveModel.saccular isEqualToString:@"noct"]) {
        if ([stultiiveModel.septuagentic isEqual: @1]) {
            imageName = @"cer_public_completed";
        } else {
            imageName = @"cer_public_normal";
        }
    } else if ([stultiiveModel.saccular isEqualToString:@"athroidlike"]) {
        if ([stultiiveModel.septuagentic isEqual: @1]) {
            imageName = @"cer_personal_completed";
        } else {
            imageName = @"cer_personal_normal";
        }
    } else if ([stultiiveModel.saccular isEqualToString:@"acerbitude"]) {
        if ([stultiiveModel.septuagentic isEqual: @1]) {
            imageName = @"cer_ext_completed";
        } else {
            imageName = @"cer_ext_normal";
        }
    } else if ([stultiiveModel.saccular isEqualToString:@"per"]) {
        if ([stultiiveModel.septuagentic isEqual: @1]) {
            imageName = @"cer_bank_completed";
        } else {
            imageName = @"cer_bank_normal";
        }
    }
    
    _iconImageView.image = [UIImage imageNamed:imageName];
}

@end
